package vn.vfriends.vbox.redis;

import javax.enterprise.inject.Disposes;
import javax.enterprise.inject.Produces;
import javax.inject.Inject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

/**
 *
 * @author tuancn
 */
public class JedisConnectionFactory {
    
    private static final Logger logger = LoggerFactory.getLogger(JedisConnectionFactory.class);
    
    @Inject
    private JedisPool jedisPool;
    
    @Produces
    public Jedis getJedis() {
        return jedisPool.getResource();
    }
    
    public void returnResouce(@Disposes Jedis jedis) {
        logger.info("Returning redis connection");
        jedisPool.returnResource(jedis);
    }
}
